package com.lc.question.dao;

import com.lc.question.pojo.Student;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository("studentDao")
public interface IStudentDao {

    @Select("select * from student")
    public List<Student> studentList();

    @Select("select * from student where stu_Id=#{stu_Id}")
    public Student findStudentById(String stu_Id);

    @Select("<script>"+
            "select * from student where 1=1"+
            "<if test='stu_name!=null and stu_name!=\"\"'>"+
                "and stu_name like CONCAT('%',#{stu_name},'%')"+
            "</if>"+
            "<if test='college!=null and college!=\"\"'>"+
                "and college=#{college}"+
            "</if>"+
            "<if test='major!=null and major!=\"\"'>"+
                "and major=#{major}"+
            "</if>"+
            "<if test='s_class!=null and s_class!=\"\"'>"+
            "and s_class=#{s_class}"+
            "</if>"+
            "<if test='grade!=null and grade!=\"\"'>"+
                "and grade=#{grade}"+
            "</if>"+
            "ORDER BY college,grade,major,s_class,stu_Id"+
            "</script>")
    public List<Student> studentListById2(Student student);

    @Select("<script>"+
            "select * from student where 1=1"+
            "<if test='stu_Id!=null and stu_Id!=\"\"'>"+
                "and stu_Id=#{stu_Id}"+
            "</if>"+
            "<if test='stu_name!=null and stu_name!=\"\"'>"+
                "and stu_name like CONCAT('%',#{stu_name},'%')"+
            "</if>"+
            "<if test='college!=null and college!=\"\"'>"+
                "and college=#{college}"+
            "</if>"+
            "<if test='major!=null and major!=\"\"'>"+
                "and major=#{major}"+
            "</if>"+
            "<if test='s_class!=null and s_class!=\"\"'>"+
                "and s_class=#{s_class}"+
            "</if>"+
            "<if test='grade!=null and grade!=\"\"'>"+
                "and grade=#{grade}"+
            "</if>"+
            "ORDER BY college,grade,major,s_class,stu_Id"+
            "</script>")
    public Student studentById(Student student);

    @Insert("insert into student(stu_Id,stu_pwd,stu_head,stu_name,stu_sex,college," +
            "major,s_class,grade,t_text)" +
            " values(#{stu_Id},#{stu_pwd},#{stu_head},#{stu_name},#{stu_sex},#{college}," +
            "#{major},#{s_class},#{grade},#{t_text})")
    public void addStudent(Student student);

    //ORDER BY convert(name using gbk) ASC

    @Select("select * from student ORDER BY college,grade,major,s_class,stu_Id")
    public List<Student> test();


}
